package 泛型;

import java.util.ArrayList;
import java.util.List;

class Students implements Comparable<Students> {
    String name;
    int age;

    Students() {

    }

    Students(String name, int age) {
        this.age = age;
        this.name = name;
    }

    void printinfo() {
        System.out.println(name + "\t" + age);
    }

    public int compareTo(Students s) {
        return this.age - s.age;
    }
}

class Pupil extends Students {
    Pupil() {

    }

    Pupil(String name, int age) {
        super(name, age);
    }
}

class MinOfList {
    public static <T extends Comparable<? super T>> T min(List<T> lst) {
        T e1 = lst.get(0);
        for (T e2 : lst) {
            if (e2.compareTo(e1) < 0) {
                e1 = e2;
            }
        }
        return e1;
    }
}

public class Gcmp {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<Students> a1 = new ArrayList<Students>();
        a1.add(new Students("Smith", 20));
        a1.add(new Pupil("Bill", 10));
        a1.add(new Students("Smith", 19));
        Students n = MinOfList.min(a1);
        System.out.println("年龄最小的学生是：");
        n.printinfo();

    }

}
